<?php

session_start();

if(!isset($_SESSION['nickname'])){
	echo '<script type="text/javascript">if(confirm("你还没有登录不能留言")){location.href ="./index.php"}</script>';exit;
}

$code = $_SESSION['code'];

$data = $_POST;

if(strtolower($code)!=strtolower($data['code'])){

	echo '<script type="text/javascript">if(confirm("验证码错误")){location.href ="./index.php"}</script>';exit;
}

exit;

$data['ctime'] = time();

include './lib/Upload.class.php';

$upload = new Upload();

$img = $upload->save();

if(!$img){
	exit($upload->errorInfo);
}

$data['img'] = $img;

$oldArr = file_get_contents("./data/db.txt");

$oldArr = json_decode($oldArr,true);

array_unshift($oldArr,$data);

$str = json_encode($oldArr);

file_put_contents("./data/db.txt",$str);

header("Location:./index.php");

// var_dump($oldArr);

